package com.dtsheep.elasticsearch.es.client.index;

import com.dtsheep.elasticsearch.es.client.ElasticsearchClientUtil;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.indices.CreateIndexRequest;
import org.elasticsearch.client.indices.CreateIndexResponse;

import java.io.IOException;

/**
 * CreateIndex
 *
 * <p>
 *     创建索引
 * </p>
 *
 * @author chuanbai
 * @date 2024/5/24
 */
public class CreateIndex {

    public static void main(String[] args) throws IOException {
        CreateIndexResponse response = ElasticsearchClientUtil.getEsClient()
                .indices()
                // 设置索引名称
                .create(new CreateIndexRequest("user"), RequestOptions.DEFAULT);
        // 响应结果
        System.out.println(response);
        // 响应状态
        System.out.println(response.isAcknowledged());
        // 响应索引名称
        System.out.println(response.index());
    }
}
